<!DOCTYPE html>
<html lang="zh-cn"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/main.css" rel="stylesheet">

    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico" />

    <title>dd命令 | wiseAI的小站</title>
</head><body><div class="container-fluid">
    <nav class="navbar fixed-top navbar-expand-sm navbar-dark bg-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <img src="/img/favicon.ico" alt="" width="30" height="24" class="d-inline-block align-text-top">
                wiseAI的小站
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/articles/">文章</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/categories/">分类</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/tags/">关键字</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/post/golang/">golang编程</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/about/">关于</a>
                    </li>
                    
                </ul>
                <form class="d-flex">
                    <input id="search-query" class="form-control me-2" type="search" placeholder="Search for anything..." aria-label="Search">
                </form>
            </div>
        </div>
    </nav>
</div>




<div id="content">
<div class="container article">
	<h1>dd命令</h1>
	<div class="post-meta">
		<div>
			
			
			By wiseai | 2023-03-20 | 1 minutes
		</div>
		<div class="tags">
			
			<a class="btn btn-light links btn-sm" href="/tags/%E5%A4%87%E4%BB%BD/">备份</a>
			
		</div>
	</div>
	<div>
		<div class="article-post">
			<p>dd：用指定大小的块拷贝一个文件，并在拷贝的同时进行指定的转换。<br>
注意：指定数字的地方若以下列字符结尾，则乘以相应的数字：b=512；c=1；k=1024；w=2<br>
参数注释：</p>
<pre><code>1. if=文件名：输入文件名，缺省为标准输入。即指定源文件。&lt; if=input file &gt;  
2. of=文件名：输出文件名，缺省为标准输出。即指定目的文件。&lt; of=output file &gt;
3. ibs=bytes：一次读入bytes个字节，即指定一个块大小为bytes个字节。
4. obs=bytes：一次输出bytes个字节，即指定一个块大小为bytes个字节。
5. bs=bytes：同时设置读入/输出的块大小为bytes个字节。
6. cbs=bytes：一次转换bytes个字节，即指定转换缓冲区大小。
7. skip=blocks：从输入文件开头跳过blocks个块后再开始复制。
8. seek=blocks：从输出文件开头跳过blocks个块后再开始复制。
   注意：通常只用当输出文件是磁盘或磁带时才有效，即备份到磁盘或磁带时才有效。
9. count=blocks：仅拷贝blocks个块，块大小等于ibs指定的字节数。
10. conv=conversion：用指定的参数转换文件。
    ascii：转换ebcdic为ascii
    ebcdic：转换ascii为ebcdic
    ibm：转换ascii为alternate ebcdic
    block：把每一行转换为长度为cbs，不足部分用空格填充
    unblock：使每一行的长度都为cbs，不足部分用空格填充
    lcase：把大写字符转换为小写字符
    ucase：把小写字符转换为大写字符
    swab：交换输入的每对字节
    noerror：出错时不停止
    notrunc：不截短输出文件
    sync：将每个输入块填充到ibs个字节，不足部分用空（NUL）字符补齐。
</code></pre>
<h1 id="例子">例子：</h1>
<ol>
<li>将本地的/dev/sda整盘备份到/dev/sdb
<code># dd if=/dev/sda of=/dev/sdb</code></li>
<li>将/dev/sda全盘数据备份到指定路径的image文件
<code># dd if=/dev/sda of=/root/image</code></li>
<li>将备份文件恢复到指定盘
<code># dd if=/root/image of=/dev/sda</code></li>
<li>备份/dev/hdb全盘数据，并利用gzip工具进行压缩，保存到指定路径
<code># dd if=/dev/sda | gzip &gt; /root/image.gz</code></li>
<li>将压缩的备份文件恢复到指定盘
<code># gzip -dc /root/image.gz | dd of=/dev/sda</code></li>
<li>备份与恢复MBR
备份：磁盘开始的512个字节大小的MBR信息到指定文件：
<code># dd if=/dev/sda of=/root/image count=1 bs=512</code>
count=1指仅拷贝一个块；bs=512指块大小为512个字节。
恢复：
<code># dd if=/root/image of=/dev/sda</code></li>
<li>制作光盘镜像
<code># dd if=/dev/cdrom of=/root/cd.iso</code></li>
<li>增加swap分区文件大小
第一步：创建一个大小为256M的文件
<code># dd if=/dev/zero of=/swapfile bs=1024k count=256</code>
第二步：把这个文件变成swap文件：
<code># mkswap /swapfile</code>
第三步：启用这个swap文件：
<code># swapon /swapfile</code>
第四步：编辑/etc/fstab文件，使在每次开机时自动加载swap文件：
<code># /swapfile swap swap default 0 0</code></li>
<li>销毁磁盘数据
<code># dd if=/dev/urandom of=/dev/hda1</code></li>
<li>测试硬盘的读写速度
<code># dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file</code>
<code># dd if=/root/1Gb.file bs=64k | dd of=/dev/null</code>
通过以上两个命令输出的命令执行时间，可以计算出硬盘的读、写速度。</li>
<li>确定硬盘的最佳块大小：</li>
</ol>
<pre tabindex="0"><code># dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
# dd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file
# dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file
# dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file
</code></pre><ol start="12">
<li>修复硬盘
<code># dd if=/dev/sda of=/dev/sda 或dd if=/dev/sdb of=/dev/sdb</code>
当硬盘较长时间(一年以上)放置不使用后，磁盘上会产生magnetic flux point，当磁头读到这些区域时会遇到困难，并可能导致I/O错误。当这种情况影响到硬盘的第一个扇区时，可能导致硬盘报废。上边的命令有可能使这些数 据起死回生。并且这个过程是安全、高效的。</li>
</ol>
<p><a href="https://www.cnblogs.com/ginvip/p/6370836.html">https://www.cnblogs.com/ginvip/p/6370836.html</a></p>

		</div>
	</div>
</div>


<div class="container">
    
    <div class="row">
        
        <div class="col-5">
            <a class="page-link link-dark text-end dh" href="/post/2023.02.27-%E5%AD%97%E4%BD%93%E4%B8%8B%E8%BD%BD%E7%BD%91%E7%AB%99/">
                <h5>前一篇</h5><br>
                字体下载网站
            </a>            
        </div>
        
        <div class="col-2">
        </div>
        
        <div class="col-5">
            <a class="page-link link-dark text-start dh" href="/post/2023.03.22-caddy%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6/">
                <h5>后一篇</h5><br>
                caddy的配置文件
            </a>            
        </div>
        
    </div>
    
</div>

        </div><br><br>
<footer class="container">
    <h2>友情链接</h2>
    <hr>
    <nav class="nav nav-pills flex-column flex-sm-row">
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/gnzg/index.html" target="_blank">孤鸟之歌</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/mm/index.html" target="_blank">生成随机字符</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/md/index.html" target="_blank">MarkDown</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/" target="_blank">Gitee</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://github.com/" target="_blank">Github</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyun.com/" target="_blank">阿里云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cloud.tencent.com/" target="_blank">腾讯云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.oschina.net/" target="_blank">OSCHINA开源中国</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/wiseai/the-way-to-go_ZH_CN/blob/master/eBook/directory.md" target="_blank">the way to go</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://topgoer.com/" target="_blank">golang文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://goframe.org/display/gf" target="_blank">GoFrame</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyundrive.com/" target="_blank">阿里云盘</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cn.vuejs.org/" target="_blank">vue3文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://element-plus.gitee.io/zh-CN/" target="_blank">element-plus文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.runoob.com/vue3/vue3-tutorial.html" target="_blank">vue3菜鸟教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://v5.bootcss.com/" target="_blank">bootstrap v5 中文文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.bootstrap.cn/" target="_blank">bootstrap文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://caddy2.dengxiaolong.com/docs/" target="_blank">caddy中文教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.58pic.com/" target="_blank">千图</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://ifonts.com/" target="_blank">iFonts</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://marketing.qiniu.com/" target="_blank">七牛云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.ixigua.com/" target="_blank">西瓜视频</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/yugang/index.html" target="_blank">鱼缸计算</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://justcc.mengkang.net/#/" target="_blank">C语言JustCC</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/pptist/" target="_blank">PPTist</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="/index.xml" target="_blank">RSS</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.kancloud.cn/idcpj/python/418553" target="_blank">参考资料</a>
        
    </nav>

    <div class="copyright text-center">
      <span class="power-by">
        Powered by <a class="links" href="https://gohugo.io" target="_blank">Hugo</a>
    </span>
    <span>|</span>
    <span>
        Theme - <a class="links" href="https://github.com/wiseai-go/blog-hugo" target="_blank">WiseAI</a>
    </span>
    <br>
    <span class="copyright-year">
        &copy;
        
        2017 -
        2023<span>
            陇ICP备15000157号
            
        </span></span>

</div>
</footer>
<script src="/js/bootstrap.bundle.min.js"></script>


</body>
</html>
